#    Copyright 2011, 2012 Tri-County Electric Cooperative, St. Matthews, South Carolina
#    This file is part of COOPWeb.
#    COOPWeb is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#    COOPWeb is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#    You should have received a copy of the GNU General Public License
#    along with COOPWeb.  If not, see <http://www.gnu.org/licenses/>.

#************************BEGIN Add Include Files to Path************************
import sys
NeededPaths=['/opt/coopweb/djangoproject/include', '/opt/coopweb/djangoproject']
for path in NeededPaths:
    if(not path in sys.path):
        sys.path.append(path)
#************************END   Add Include Files to Path************************
import os, csv, shutil, datetime, time, reportlab, djangoproject.settings, random
from django.contrib.gis.db import models
from django.contrib.gis.geos import *
from django.http import HttpResponse
from django.contrib import admin
from django.template import Context, loader
import djangoproject.settings
from models import *
from django import forms
import django
import djangoproject
from django.shortcuts import redirect
import httplib







def COOPTalkView(request):
    """COOPTalk View handles incoming COOPTalk requests"""
    if(not request.is_secure()):
        return redirect(djangoproject.settings.COOPWebSecureWebsiteName)

    Input=str(request.POST)
    ActualResponse=''
    cOOPTalk = COOPTalk()
    if('<PingURL xmlns="http://www.multispeak.org/Version_3.0" />' in Input):
        Response=cOOPTalk.InResponsePingURL(Input)
    elif('<GetMethods xmlns="http://www.multispeak.org/Version_3.0" />' in Input):
        Response=cOOPTalk.InResponseGetMethods(Input)
    elif('<ReadingChangedNotification xmlns="http://www.multispeak.org/Version_3.0">' in Input):
        try:
            Response=cOOPTalk.InResponseReadingChangedNotification(Input)
        except:
            Response=('An Exception Occurred.' + str(sys.exc_info()[0]))
            ActualResponse='An Exception Occurred.'
    else:
        Response=cOOPTalk.InResponsePingURL(Input)



    if(ActualResponse):
        Response=ActualResponse
    return HttpResponse(Response, mimetype='text/xml')










